/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "stdafx.h"
#include "属性.h"



void f_prop_Release(S_Props& prop) {
	DEF_release_Props_UI_Ptr(prop);
	prop.m_UI = nullptr;

	switch (prop.m_Type) {
	case E_值类型::e_Type_Enum:
		f_release_EnumProp(prop);
		break;
	case E_值类型::e_Type_MapPtr_Array1D:
		f_StrIndexProp_release(prop);
		break;
	case E_值类型::e_Type_映射引用_2D:
		f_prop_映射引用2D_release(prop);
		break;
	case E_值类型::e_Type_UI8_Array1D:
		delete[] (S_PropVecU8*)prop.m_Value;
		return;
	case E_值类型::e_Type_Bool_1D:
		delete[] (S_PropVecBool*)prop.m_Value;
		return;
	case E_值类型::e_Type_PropContainer:
		delete (S_PropContainer*)prop.m_Value;
		return;
	case E_值类型::e_Type_PropList:
		delete (S_PropList*)prop.m_Value;
		return;
	case E_值类型::e_Type_2D曲线:
		f_an_销毁曲线A((S_曲线*)prop.m_Value);
		return;
	case E_值类型::e_Type_2D曲线1D:
		f_an_销毁曲线层((S_动画曲线组*)prop.m_Value);
		return;
	default:
		break;
	}

	if(prop.m_值映射类型) return;
	
	free(prop.m_Value);
}



std::wstring f_core_get属性到文本(S_Props prop, uint8 分量) {
	std::wstring text;

	switch (prop.m_Type) {
	case E_值类型::e_Type_I8: text = f_整数值转宽字符串(*(int8*)prop.m_Value); break;
	case E_值类型::e_Type_UI8: text = f_整数值转宽字符串(*(uint8*)prop.m_Value); break;
	case E_值类型::e_Type_I16: text = f_整数值转宽字符串(*(int16*)prop.m_Value); break;
	case E_值类型::e_Type_UI16: text = f_整数值转宽字符串(*(uint16*)prop.m_Value); break;
	case E_值类型::e_Type_I32: text = f_整数值转宽字符串(*(int32*)prop.m_Value); break;
	case E_值类型::e_Type_UI32: text = f_整数值转宽字符串(*(uint32*)prop.m_Value); break;
		//case E_值类型::e_插座Type_I64: text = f_整数值转宽字符串w(*(int64*)editBox->m_Value.m_Value); break;
	case E_值类型::e_Type_UI64: text = f_整数值转宽字符串64(*(uint64*)prop.m_Value); break;

	case E_值类型::e_Type_F32: text = f_浮点数值转宽字符串(*(float32*)prop.m_Value); break;
	case E_值类型::e_Type_RGB:
	case E_值类型::e_Type_Vec2:
	case E_值类型::e_Type_Vec3: text = f_浮点数值转宽字符串(((float32*)prop.m_Value)[分量]); break;

	case E_值类型::e_Type_iVec2:
	case E_值类型::e_Type_iVec3:
	case E_值类型::e_Type_iVec4: text = f_整数值转宽字符串(((int32*)prop.m_Value)[分量]); break;
	case E_值类型::e_Type_uVec2:
	case E_值类型::e_Type_uVec3:
	case E_值类型::e_Type_uVec4: text = f_整数值转宽字符串(((uint32*)prop.m_Value)[分量]); break;
	}

	return text;
}

void f_core_字符串到属性(S_Props& prop, const std::wstring& text, uint8 分量)
{
	switch (prop.m_Type) {
	case E_值类型::e_Type_I8: f_prop_I8(prop) = f_字符串转I32(text); break;
	case E_值类型::e_Type_UI8: f_prop_UI8(prop) = f_字符串转I32(text); break;
	case E_值类型::e_Type_I16: f_prop_I16(prop) = f_字符串转I32(text); break;
	case E_值类型::e_Type_UI16: f_prop_UI16(prop) = f_字符串转I32(text); break;
	case E_值类型::e_Type_I32: f_prop_I32(prop) = f_字符串转I32(text); break;
	case E_值类型::e_Type_UI32: f_prop_UI32(prop) = f_字符串转I32(text); break;
		//case E_值类型::e_插座Type_I64: text = f_整数值转宽字符串w(*(int64*)editBox->m_Value.m_Value); break;
	case E_值类型::e_Type_UI64: f_prop_UI64(prop) = f_字符串转I32(text); break;

	case E_值类型::e_Type_F32: f_prop_F32(prop) = f_字符串转F32(text); break;
	case E_值类型::e_Type_Vec2:
	case E_值类型::e_Type_Vec3: ((float32*)prop.m_Value)[分量] = f_字符串转F32(text); break;
	case E_值类型::e_Type_iVec2:
	case E_值类型::e_Type_iVec3:
	case E_值类型::e_Type_iVec4: ((int32*)prop.m_Value)[分量] = f_字符串转I32(text); break;
	case E_值类型::e_Type_uVec2:
	case E_值类型::e_Type_uVec3:
	case E_值类型::e_Type_uVec4: ((uint32*)prop.m_Value)[分量] = f_字符串转I32(text); break;
	}
}












S_Props f_prop_创建物体类型属性数据() {
	S_Props prop = f_alloc_EnumProp(nullptr, {
		{ L"空", "" },
		{ L"网格", "" },
		{ L"平行光", ""},
		{ L"聚光灯", ""},
		{ L"点光源", ""},
		{ L"面光源", ""},

		{ L"实例", ""},
		{ L"线", ""},
		{ L"线段", ""},
		{ L"粒子", ""},
		{ L"摄像机", ""},

		}
	, L"物理几何类型", 0);

	return prop;
}




